package com.zilue.payment.gateway.method.order;

import com.zilue.payment.gateway.domain.CorpDO;
import com.zilue.payment.gateway.exception.BizManagerException;
import com.zilue.payment.gateway.manage.OrderCreateManager;
import com.zilue.payment.gateway.method.BaseMethod;
import com.zilue.payment.gateway.paramter.BaseParameter;
import com.zilue.payment.gateway.paramter.order.CreateParameter;
import com.zilue.payment.gateway.reurndata.PublicReturn;
import com.zilue.payment.gateway.reurndata.enums.RequestStatusEnum;
import com.zilue.payment.gateway.reurndata.order.CreateReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by zilue on 2017/3/7.
 */
@Service("hfpay.trade.order.create")
public class Create implements BaseMethod {
    @Autowired
    private OrderCreateManager orderCreateManager;

    @Override
    public PublicReturn doMethod(CorpDO corpDO, BaseParameter baseParameter) {
        try {
            CreateParameter createParameter = (CreateParameter) baseParameter;
            return orderCreateManager.createOrder(corpDO, createParameter);
        } catch (BizManagerException ex) {
            CreateReturn createReturn = new CreateReturn(RequestStatusEnum.RequestSuccess);
            createReturn.setBusinessStatus(ex.getBusinessStatusEnum());
            createReturn.appendSub_msg(ex.getAppendMsg());
            return createReturn;
        }

    }

    @Override
    public Class<? extends BaseParameter> paramterClass() {
        return CreateParameter.class;
    }
}
